package com.df.base.common;

import java.util.concurrent.ConcurrentHashMap;

public class GameReqScriptManager {

    private GameReqScriptManager(){}
    enum Singleton{
        INSTANCE;
        public GameReqScriptManager manager = new GameReqScriptManager();
    }

    public static GameReqScriptManager getInstance(){
        return Singleton.INSTANCE.manager;
    }

    /**
     * 请求路径hash值与脚本映射
     */
    public ConcurrentHashMap<Integer,IScript> pathId2Script = new ConcurrentHashMap<>();

    /**
     * 请求路径hash值与路径映射
     */
    public ConcurrentHashMap<Integer,String> pathID2Path = new ConcurrentHashMap<>();

    public void addScript(Integer id,String path,IScript script){
        if(pathId2Script.contains(id)){//替换
            pathId2Script.put(id,script);
            return;
        }
        pathId2Script.put(id,script);
        pathID2Path.put(id,path);
    }

    public IScript getScript(Integer id){
        if(id==null) return null;
        return pathId2Script.get(id);
    }
    public IScript getScript(String path){
        if(path==null) return null;
        return pathId2Script.get(path.hashCode());
    }

    public String getPath(Integer id){
        if(id==null) return null;
        return pathID2Path.get(id);
    }

    public Integer getScriptId(String path){
        if(path==null) return null;
        return path.hashCode();
    }
}
